<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        /* 
            需求1：将cc替换为ss
            const str = "aabbccddffaa";
            思路：首先思考有没有现成的方法，如果有，就直接使用，没有就自己写
         */
        //replace(pattern, replacement)
        //  const str = "aabbccddffaa";
        //  const result = str.replace("cc",'ss');     //不会改变字符串本身，返回一个新的字符串
        //  console.log(result)

        /* replaceAll: 替换所有的字符
           需求2：将所有的aa替换为zz
         */
        //   console.log(str.replaceAll('aa','zz'))

        /* 
          需求：提取字符串的一部分内容
          const str = "abcdefg";
         */
        /*          const str = "abcdefg";
                 const sliceStr = str.slice(2)
                 console.log(sliceStr)    //cdefg
                 console.log(str) //原本的字符串没有改变
                 */


        /* 
             需求：把字符串按照 ， 进行切割
             const str = "a,b,c,d,e,f"

         */
        /*           const str = "a,b,c,d,e,f"
                  const words = str.split(",")
                  console.log(words) */


        const str = 'The quick brown fox jumps over the lazy dog.';

        const words = str.split(' ');
        console.log(words);         //['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog.']
        console.log(words[3]);

        // const chars = str.split('');
        // console.log(chars[8]);

        const strCopy = str.split();     //就相当于 str.split(' ');
        console.log(strCopy);       //['The quick brown fox jumps over the lazy dog.']


        const str2 ="a,b,c,d,e,f";
        const str2Arr = str2.split();
        console.log(str2Arr)    //['a,b,c,d,e,f']   没有进行切割
    </script>
</head>

<body>

</body>

</html>